﻿using AngryManagementMayhem.Content.Textures.MainMenu;
using Transformable_Engine_v2.Engine.GameObjects.Containers;
using Transformable_Engine_v2.Engine.GameObjects.Containers.Transformable_controls;
using Transformable_Engine_v2.Engine.Graphics;
using Transformable_Engine_v2.Engine.Transformable_Math.Geometry;

namespace AngryManagementMayhem.GameCode.Screens.MainMenuScreen.MainMenuObjects
{
    public class CreateButton : Container
    {
        private readonly ImageContainer _buttonLeft;
        private readonly ImageContainer _buttonCenter;
        private readonly ImageContainer _buttonRight;

        public CreateButton(string text)
         {
             const float buttonSize = 9;
             _buttonLeft = new ImageContainer
                 {
                     Sprite = MainMenuSpriteSheet.GetSprite(MainMenuSpriteSheet.SpriteList.ButtonLeft)
                 };

             _buttonCenter = new ImageContainer
             {
                 PositionGridBound = new TE_Vector2(1, 0),
                 Sprite = MainMenuSpriteSheet.GetSprite(MainMenuSpriteSheet.SpriteList.ButtonCenter),
                 Scale = new TE_Vector2(buttonSize - 2, 1),
             };

             _buttonRight = new ImageContainer
             {
                 PositionGridBound = new TE_Vector2(buttonSize, 0),
                 Sprite = MainMenuSpriteSheet.GetSprite(MainMenuSpriteSheet.SpriteList.ButtonRight),
                 Origin = TE_Rectangle.Alignment.TopRight,
             };

             AddChildren(_buttonLeft, _buttonRight, _buttonCenter);

             AddChildren(new Label(MainMenuSpriteSheet.GetSprite, text)
                 {
                     PositionGridBound = new TE_Vector2(buttonSize / 2, 1),
                     TextAlign = TE_Rectangle.Alignment.CenterMiddle
                 });

             BoundingBox = new TE_Rectangle(0, 0, buttonSize, 2);

             HoverOutColor();
         }

         protected override void OnMouseEnter(TE_Vector2 mousePosition)
         {
             HoverInColor();
             base.OnMouseEnter(mousePosition);
         }

         protected override void OnMouseLeave(TE_Vector2 mousePosition)
         {
             HoverOutColor();
             base.OnMouseLeave(mousePosition);
         }

        void HoverOutColor()
        {
            Color c = new Color(0, 74, 127);
            _buttonLeft.Color = c;
            _buttonCenter.Color = c;
            _buttonRight.Color = c;
        }

        void HoverInColor()
        {
            Color c = new Color(0, 148, 255);
            _buttonLeft.Color = c;
            _buttonCenter.Color = c;
            _buttonRight.Color = c;
        }
    }
}